{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f48833f2-3a6b-4c4e-ae70-883006ad4ca5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://search.jd.com/search?keyword=京东&enc=utf-8\n",
      "200\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "url = 'https://search.jd.com/search'\n",
    "#以字典存储查询的关键词及属性\n",
    "qrydata = {\n",
    "    'keyword':'京东',\n",
    "    'enc':'utf-8',\n",
    "}\n",
    "lt = []\n",
    "for k,v in qrydata.items():\n",
    "    lt.append(k+'='+str(v))\n",
    "query_string = '&'.join(lt)\n",
    "url = url + '?'+query_string\n",
    "print(url)\n",
    "r=requests.get(url)\n",
    "print(r.status_code)\n",
    "fb=open(\"C:\\\\Users\\\\Administrator\\\\Desktop\\\\爬虫\\\\京东.html\",\"wb\")\n",
    "fb.write(r.content)\n",
    "fb.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac7a3f5d-e9f8-4731-918c-0f59df10dacd",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
